package com.example.Flyweight;

import java.util.Random;

/**
 * Flyweight 享元模式
 * https://www.runoob.com/design-pattern/flyweight-pattern.html
 */
public class app {
    public static void main(String[] args) {
        String[] colors = new String[]{"Red", "Green", "Pink", "Black", "White"};
        // Shape circle = ShapeFactory.getCircle(colors[new Random().nextInt(colors.length)]);
        for (int i = 0; i < 20; i++) {
            String color = colors[random(colors.length)];
            Circle circle = (Circle) ShapeFactory.getCircle(color);
            circle.setParam(random(10), random(10), random(10));
            circle.draw();
        }
    }

    public static int random(int bound) {
        return new Random().nextInt(bound);
    }
}
